package com.beauty.mapper;

import com.beauty.models.Note;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface INoteMapper {
    /**
     * 查询单个笔记
     *
     * @param id
     * @return
     */
    @Select("SELECT * FROM note WHERE id = #{id}")
    Note selectNote(String id);

    /**
     * 通过UserId查询笔记
     *
     * @param userId
     * @return
     */
    @Select("SELECT * FROM note WHERE userId = #{userId}  LIMIT #{offset}, #{pageSize}")
    List<Note> selectNoteListByUserId(int offset, int pageSize, String userId);

    /**
     * 查询笔记
     *
     * @param offset
     * @param title
     * @param pageSize
     * @return
     */
    @Select("SELECT * FROM note WHERE title LIKE '%${title}%' ORDER BY createDate DESC LIMIT #{offset}, #{pageSize}")
    List<Note> selectNoteList(int offset, String title, int pageSize);

    /**
     * 查询数量
     *
     * @param title
     * @param userId
     * @return
     */
    @Select("SELECT COUNT(*) FROM note WHERE title LIKE '%${title}%' AND userId LIKE '%${userId}%'")
    int selectNoteListCount(String title, String userId);

    /**
     * 插入笔记
     *
     * @param id
     * @param title
     * @param content
     * @param createDate
     * @param userId
     * @param fav
     * @return
     */
    @Select("INSERT INTO note VALUES (#{id},#{title},#{content},#{createDate},#{userId},#{fav})")
    List<Note> insertNote(String id, String title, String content, long createDate, String userId, int fav);

    /**
     * 删除笔记
     *
     * @param noteId
     */
    @Select("DELETE FROM note WHERE id = #{noteId}")
    void deleteNote(String noteId);

}
